package org.webdb.jdbc.impl;

import java.util.HashMap;
import java.util.Map;

import org.webdb.jdbc.JDBCSqlFactory;
import org.webdb.jdbc.JDBCSqlProvider;

import com.healthmarketscience.sqlbuilder.dbspec.basic.DbSpec;

public class SqlAnsi92_SqlFactory implements JDBCSqlFactory {

    private Map<String, DbSpec> map = new HashMap<String, DbSpec>();

    public String[] getSupported() {
        return new String[] { "*" };
    }

    public JDBCSqlProvider createProvider(String name) {
        return new SqlAnsi92_SqlProvider(getDbSpec(name));
    }

    private DbSpec getDbSpec(String name) {
        DbSpec dbSpec = map.get(name);
        if (dbSpec == null)
            synchronized (this) {
                dbSpec = map.get(name);
                if (dbSpec == null) {
                    map.put(name, dbSpec = new DbSpec());
                }
            }

        return dbSpec;
    }

}
